package com.googlecode.maratische.google.listeners;

import java.util.ArrayList;
import java.util.List;

import com.googlecode.maratische.google.BaseException;
import com.googlecode.maratische.google.model.Credentials;
import com.googlecode.maratische.google.model.Item;
import com.googlecode.maratische.google.model.Label;
import com.googlecode.maratische.google.model.Spam;

public class MainFrameObservable {

	private List<MainFrameListener> listeners = new ArrayList<MainFrameListener>();
	
	public void addObserver(MainFrameListener listener) {
		listeners.add(listener);
	}

	public void showError(Exception e) {
		for (MainFrameListener listener : listeners) {
			listener.showError(e);
		}
	}

	public void showError(String text, Exception e) {
		for (MainFrameListener listener : listeners) {
			listener.showError(text, e);
		}
	}

	public void updateFeedMenu() {
		for (MainFrameListener listener : listeners) {
			listener.updateFeedMenu();
		}
	}

	public void updateItemsPanel() {
		for (MainFrameListener listener : listeners) {
			listener.updateItemsPanel();
		}
	}

	public void itemsPanelClearSelection() {
		for (MainFrameListener listener : listeners) {
			listener.itemsPanelClearSelection();
		}
	}
	
	public Credentials loginForm(String errorMessage) {
		for (MainFrameListener listener : listeners) {
			return listener.loginForm(errorMessage);
		}
		return null;
	}
	
	public void updateOfflineButton() throws BaseException {
		for (MainFrameListener listener : listeners) {
			listener.updateOfflineButton();
		}
	}
	
	@Deprecated
	public void setItemsToItemList(List<Item> items) {
		for (MainFrameListener listener : listeners) {
			listener.setItemsToItemList(items);
		}
	}
	
	public void doFullScreenMode() {
		for (MainFrameListener listener : listeners) {
			listener.doFullScreenMode();
		}
	}
	
	public void doExpandWindow() {
		for (MainFrameListener listener : listeners) {
			listener.doExpandWindow();
		}
	}
	
	public void doExpandItems(boolean expand) {
		for (MainFrameListener listener : listeners) {
			listener.doExpandItems(expand);
		}
	}

	public void viewSourceCodeFrame(String title, String description) {
		for (MainFrameListener listener : listeners) {
			listener.viewSourceCodeFrame(title, description);
		}
	}
	public Label openLabelForm(Item selectedItem) {
		for (MainFrameListener listener : listeners) {
			return listener.openLabelForm(selectedItem);
		}
		return null;
	}
	
	public Spam openSpamForm() {
		for (MainFrameListener listener : listeners) {
			return listener.openSpamForm();
		}
		return null;
	}
	
	public boolean openNotLabelForm(Item selectedItem) {
		for (MainFrameListener listener : listeners) {
			return listener.openNotLabelForm(selectedItem);
		}
		return false;
	}
}
